{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandasのデータ構造\n",
    "* Series(シリーズ)\n",
    "    * 一次元のデータ構造\n",
    "* DataFrame(データフレーム)\n",
    "    * 二次元のデータ構造\n",
    "    * 使うのはほとんどこれ\n",
    "* 階層インデックス\n",
    "    * より高次元のデータを扱うとき\n",
    "    \n",
    "## 文言について\n",
    "\n",
    "* インデックス : 行\n",
    "* カラム : 列\n",
    "* 行番号 : 数値のインデックス\n",
    "* 列番号 : 数値のカラム\n",
    "* 行ラベル : 文字列のインデックス\n",
    "* 列ラベル : 文字列のカラム"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## データフレームの作成(初期化)\n",
    "\n",
    "pandasをロードし、pdという名前でアクセスできるようにする\n",
    "```\n",
    "import pandas as pd\n",
    "```\n",
    "\n",
    "* データフレームとして扱いたいデータを `pd.DataFrame` に渡す\n",
    "    * 戻り値はデータフレームのオブジェクト"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### データフレームの作成の基本\n",
    "\n",
    "* 1列のみ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0\n",
       "0  1\n",
       "1  2\n",
       "2  3"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([1,2,3])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* columnsで列名を指定する"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   value\n",
       "0      1\n",
       "1      2\n",
       "2      3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([1,2,3], columns=['value'])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### データフレームにタプルのリストを渡す\n",
    "\n",
    "* 複数列作成する場合\n",
    "    * <font color=\"red\">列名はcolumnsで指定する</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* リストの中にタプルを入れて渡すと行に値が入る"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0  1  2\n",
       "0  1  2  3"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([(1,2,3)])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* columonsで列名を指定する"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>value1</th>\n",
       "      <th>value2</th>\n",
       "      <th>value3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   value1  value2  value3\n",
       "0       1       2       3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([(1,2,3)], columns=['value1','value2','value3'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     name  price\n",
       "0   apple    160\n",
       "1  orange     30\n",
       "2    kiwi     80"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame([('apple',160),('orange',30),('kiwi',80)], columns=['name', 'price'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>price</th>\n",
       "      <th>color</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>160</td>\n",
       "      <td>red</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>orange</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>80</td>\n",
       "      <td>green</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     name  price   color\n",
       "0   apple    160     red\n",
       "1  orange     30  orange\n",
       "2    kiwi     80   green"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = [\n",
    "    ('apple',160,'red'),\n",
    "    ('orange',30,'orange'),\n",
    "    ('kiwi',80,'green')\n",
    "]\n",
    "\n",
    "pd.DataFrame(data, columns=['name', 'price','color'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### データフレームにディクショナリのリストを渡す\n",
    "\n",
    "* 複数列作成する場合\n",
    "    * <font color=\"red\">列名はディクショナリのキーで指定する</font>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'order': [12, 30, 8], 'price': [160, 30, 80], 'fruit': ['apple', 'orange', 'kiwi']}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price\n",
       "0   apple     12    160\n",
       "1  orange     30     30\n",
       "2    kiwi      8     80"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "print(data)\n",
    "pd.DataFrame(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CSVから読み込む\n",
    "\n",
    "* ヘッダの指定が無い場合は1行目がヘッダ(列名)となる\n",
    "    * header = None をつけると自動的に数字のヘッダが割り振られる"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['A1', 'B1', 'C1'], ['A2', 'B2', 'C2'], ['A3', 'B3', 'C3'], ['A4', 'B4', 'C4']]\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "\n",
    "data_list = []\n",
    "for i in range(1,5):\n",
    "    data = [h + str(i) for h in \"ABC\"]\n",
    "    #print(data)\n",
    "    data_list.append(data)\n",
    "print(data_list)\n",
    "\n",
    "with open('csv/test.csv', mode='w', encoding='utf-8') as fp:\n",
    "    csv_write = csv.writer(fp, lineterminator=\"\\n\")\n",
    "    csv_write.writerows(data_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A1,B1,C1\n",
      "A2,B2,C2\n",
      "A3,B3,C3\n",
      "A4,B4,C4\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "cat csv/test.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    0   1   2\n",
      "0  A1  B1  C1\n",
      "1  A2  B2  C2\n",
      "2  A3  B3  C3\n",
      "3  A4  B4  C4\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## CSVに書き込む"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = [\n",
    "    ('apple',160,'red'),\n",
    "    ('orange',30,'orange'),\n",
    "    ('kiwi',80,'green')\n",
    "]\n",
    "\n",
    "df = pd.DataFrame(data, columns=['name', 'price','color'])\n",
    "df = df.set_index('name')\n",
    "df.to_csv('csv/write_csv.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name,price,color\n",
      "apple,160,red\n",
      "orange,30,orange\n",
      "kiwi,80,green\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "cat csv/write_csv.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 後から列を追加する\n",
    "\n",
    "### データフレーム内の演算結果を追加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "      <th>total</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "      <td>1920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "      <td>900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "      <td>640</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price  total\n",
       "0   apple     12    160   1920\n",
       "1  orange     30     30    900\n",
       "2    kiwi      8     80    640"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df['total'] = df['order'] * df['price']\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 別のデータフレームと結合\n",
    "\n",
    "* 「pandas_join.ipynb」を参照"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## データフレーム列の型を調べる"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "fruit    object\n",
       "order     int64\n",
       "price     int64\n",
       "dtype: object"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "pd.DataFrame(data).dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 3 entries, 0 to 2\n",
      "Data columns (total 3 columns):\n",
      "fruit    3 non-null object\n",
      "order    3 non-null int64\n",
      "price    3 non-null int64\n",
      "dtypes: int64(2), object(1)\n",
      "memory usage: 152.0+ bytes\n"
     ]
    }
   ],
   "source": [
    "pd.DataFrame(data).info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## インデックス\n",
    "\n",
    "### インデックスを指定する\n",
    "\n",
    "* デフォルトは行の検索は0から始まる数値\n",
    "    * 任意の値をインデックスにセットできる"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>apple</th>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orange</th>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kiwi</th>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        order  price\n",
       "apple      12    160\n",
       "orange     30     30\n",
       "kiwi        8     80"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data, index=['apple', 'orange', 'kiwi'])\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 特定の列をインデックスにする"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>fruit</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>apple</th>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>orange</th>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>kiwi</th>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        order  price\n",
       "fruit               \n",
       "apple      12    160\n",
       "orange     30     30\n",
       "kiwi        8     80"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df = df.set_index('fruit')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "order     8\n",
       "price    80\n",
       "Name: kiwi, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data, index=['apple', 'orange', 'kiwi'])\n",
    "df.ix['kiwi']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3, 2)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data, index=['apple', 'orange', 'kiwi'])\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## インデックスとカラムを指定する"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A1,B1,C1\n",
      "A2,B2,C2\n",
      "A3,B3,C3\n",
      "A4,B4,C4\n",
      "------------------\n",
      "row_name,col_0,col_1,col_2\n",
      "row_0,A1,B1,C1\n",
      "row_1,A2,B2,C2\n",
      "row_2,A3,B3,C3\n",
      "row_3,A4,B4,C4\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "cat csv/test.csv\n",
    "echo \"------------------\"\n",
    "cat csv/test2.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ヘッダや列名の無いデータでインデックスとカラムを指定\n",
    "\n",
    "* ヘッダ行が無いのでheader = Noneとしている\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    0   1   2\n",
      "0  A1  B1  C1\n",
      "1  A2  B2  C2\n",
      "2  A3  B3  C3\n",
      "3  A4  B4  C4\n",
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df2 = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "\n",
    "df2.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df2.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "print(df)\n",
    "print(df2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### ヘッダ行と任意の列でインデックスとカラムを指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         col_0 col_1 col_2\n",
      "row_name                  \n",
      "row_0       A1    B1    C1\n",
      "row_1       A2    B2    C2\n",
      "row_2       A3    B3    C3\n",
      "row_3       A4    B4    C4\n",
      "      row_name col_0 col_2\n",
      "col_1                     \n",
      "B1       row_0    A1    C1\n",
      "B2       row_1    A2    C2\n",
      "B3       row_2    A3    C3\n",
      "B4       row_3    A4    C4\n",
      "  col_1 row_name col_0 col_2\n",
      "0    B1    row_0    A1    C1\n",
      "1    B2    row_1    A2    C2\n",
      "2    B3    row_2    A3    C3\n",
      "3    B4    row_3    A4    C4\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test2.csv\")\n",
    "df1 = df.set_index(\"row_name\")\n",
    "df2 = df.set_index(\"col_1\")\n",
    "\n",
    "print(df1)\n",
    "print(df2)\n",
    "\n",
    "# indexをリセット\n",
    "print(df2.reset_index())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## データフレームの構造確認"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n",
      "Index(['row_0', 'row_1', 'row_2', 'row_3'], dtype='object')\n",
      "Index(['col_0', 'col_1', 'col_2'], dtype='object')\n",
      "4\n",
      "3\n",
      "(4, 3)\n",
      "12\n",
      "Index    32\n",
      "col_0    32\n",
      "col_1    32\n",
      "col_2    32\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "print(df)\n",
    "\n",
    "# 行名\n",
    "print(df.index)\n",
    "\n",
    "# 列名\n",
    "print(df.columns)\n",
    "\n",
    "# 行数\n",
    "print(len(df))\n",
    "\n",
    "# 列数\n",
    "print(len(df.columns))\n",
    "\n",
    "# 行・列数\n",
    "print(df.shape)\n",
    "\n",
    "# 要素数\n",
    "print(df.size)\n",
    "\n",
    "# メモリ使用量\n",
    "print(df.memory_usage())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## データフレームの内部データとリスト化\n",
    "\n",
    "* データフレーム -> ndarray -> リスト\n",
    "    * valuesメソッド\n",
    "        * データフレームからndarrayを取得する\n",
    "            * データフレームは単純な値以外の情報も持っているのでndarrayより容量が大きい\n",
    "* リスト -> データフレーム\n",
    "* ndarray -> データフレーム\n",
    "    * dataframeメソッド\n",
    "        * indexとcolumnsも指定できる"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n",
      "[['A1' 'B1' 'C1']\n",
      " ['A2' 'B2' 'C2']\n",
      " ['A3' 'B3' 'C3']\n",
      " ['A4' 'B4' 'C4']]\n",
      "[['A1', 'B1', 'C1'], ['A2', 'B2', 'C2'], ['A3', 'B3', 'C3'], ['A4', 'B4', 'C4']]\n",
      "------------------\n",
      "Index    32\n",
      "col_0    32\n",
      "col_1    32\n",
      "col_2    32\n",
      "dtype: int64\n",
      "96\n",
      "------------------\n",
      "    0   1   2\n",
      "0  A1  B1  C1\n",
      "1  A2  B2  C2\n",
      "2  A3  B3  C3\n",
      "3  A4  B4  C4\n",
      "    0   1   2\n",
      "0  A1  B1  C1\n",
      "1  A2  B2  C2\n",
      "2  A3  B3  C3\n",
      "3  A4  B4  C4\n",
      "------------------\n",
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "nd_ary = df.values\n",
    "nd_ary_to_list = df.values.tolist()\n",
    "\n",
    "print(df)\n",
    "print(nd_ary)\n",
    "print(nd_ary_to_list)\n",
    "\n",
    "print(\"------------------\")\n",
    "print(df.memory_usage())\n",
    "print(nd_ary.nbytes)\n",
    "\n",
    "print(\"------------------\")\n",
    "list_to_df = pd.DataFrame(nd_ary_to_list)\n",
    "nd_ary_to_df = pd.DataFrame(nd_ary)\n",
    "print(list_to_df)\n",
    "print(nd_ary_to_df)\n",
    "\n",
    "print(\"------------------\")\n",
    "list_to_df_with_index_col = pd.DataFrame(nd_ary_to_list, index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"], columns = [\"col_0\", \"col_1\", \"col_2\"])\n",
    "print(list_to_df_with_index_col)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本的な統計量の一覧表示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>A3</td>\n",
       "      <td>B4</td>\n",
       "      <td>C3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0 col_1 col_2\n",
       "count      4     4     4\n",
       "unique     4     4     4\n",
       "top       A3    B4    C3\n",
       "freq       1     1     1"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "print(df)\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        0  1  2   3\n",
       "count   4  4  4   4\n",
       "unique  3  3  3   4\n",
       "top     1  2  3  16\n",
       "freq    2  2  2   1"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame([['1', '2', '3', '4'], ['1', '2', '3', '8'], ['9', '10', '11', '12'], ['13', '14', '15', '16']])\n",
    "df.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 値の参照"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 単独の値\n",
    "    * at : 行名、列名を指定して参照\n",
    "    * iat : 行番号、列番号を指定して参照\n",
    "* 複数の値\n",
    "    * loc : 行名、列名の範囲を指定して参照\n",
    "    * iloc : 行番号、列番号の範囲を指定して参照\n",
    "        * at, iatと同じように単独の値も取得できる\n",
    "        * ただし、単独の値の場合はat, iatの方が処理が速い\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n",
      "C1\n",
      "C3\n",
      "C1\n",
      "C3\n",
      "------------------------\n",
      "col_1    B1\n",
      "col_2    C1\n",
      "Name: row_0, dtype: object\n",
      "row_0    A1\n",
      "row_3    A4\n",
      "Name: col_0, dtype: object\n",
      "------------------------\n",
      "      col_1 col_2\n",
      "row_0    B1    C1\n",
      "------------------------\n",
      "      col_1 col_2\n",
      "row_0    B1    C1\n",
      "row_1    B2    C2\n",
      "------------------------\n",
      "      col_1 col_2\n",
      "row_0    B1    C1\n",
      "row_1    B2    C2\n",
      "row_2    B3    C3\n",
      "------------------------\n",
      "      col_1 col_2\n",
      "row_0    B1    C1\n",
      "row_3    B4    C4\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "print(df)\n",
    "\n",
    "# at\n",
    "print(df.at[\"row_0\", \"col_2\"])\n",
    "print(df.iat[2, 2])\n",
    "\n",
    "# locで単独の値参照。atより遅いらしい\n",
    "print(df.loc[\"row_0\", \"col_2\"])\n",
    "print(df.iloc[2, 2])\n",
    "\n",
    "print(\"------------------------\")\n",
    "# locで範囲指定\n",
    "## row_0行のcol_1～col_2列の値を参照\n",
    "print(df.loc[\"row_0\", \"col_1\":\"col_2\"])\n",
    "## row_0とrow_3行のcol_0列の値を参照\n",
    "print(df.loc[[\"row_0\", \"row_3\"], \"col_0\"])\n",
    "\n",
    "# ilocで範囲指定\n",
    "print(\"------------------------\")\n",
    "print(df.iloc[:1, 1:3])\n",
    "print(\"------------------------\")\n",
    "print(df.iloc[:2, 1:3])\n",
    "print(\"------------------------\")\n",
    "print(df.iloc[:3, 1:3])\n",
    "print(\"------------------------\")\n",
    "print(df.iloc[::3, 1:3])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 特定の列や行を取り出す"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 取り出す列名を指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order\n",
       "0   apple     12\n",
       "1  orange     30\n",
       "2    kiwi      8"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df[['fruit','order']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 先頭行から取り出す行数を指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price\n",
       "0   apple     12    160\n",
       "1  orange     30     30"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df.head(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 最後の行から取り出す行数を指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price\n",
       "1  orange     30     30\n",
       "2    kiwi      8     80"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df.tail(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 取り出す行を範囲で指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price\n",
       "0   apple     12    160\n",
       "1  orange     30     30"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 1～3行目を表示\n",
    "df[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>orange</td>\n",
       "      <td>30</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    fruit  order  price\n",
       "1  orange     30     30\n",
       "2    kiwi      8     80"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 2行目以降を表示\n",
    "df[1:]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### サンプル行を取り出す"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   fruit  order  price\n",
       "0  apple     12    160\n",
       "2   kiwi      8     80"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# ランダムに2行取り出す\n",
    "df.sample(n=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 値を比較して取り出す、適当な値で補完する"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12</td>\n",
       "      <td>160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   fruit  order  price\n",
       "0  apple     12    160\n",
       "2   kiwi      8     80"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "df[df.price > 50]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12.0</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   fruit  order  price\n",
       "0  apple   12.0  160.0\n",
       "1    NaN    NaN    NaN\n",
       "2   kiwi    8.0   80.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 条件を満たさない行はNaNで表示。実数になる。\n",
    "df.where(df.price > 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12.0</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   fruit  order  price\n",
       "0  apple   12.0  160.0\n",
       "2   kiwi    8.0   80.0"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 条件を満たさない行を表示しない\n",
    "df.where(df.price > 50).dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fruit</th>\n",
       "      <th>order</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>apple</td>\n",
       "      <td>12.0</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>72.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>kiwi</td>\n",
       "      <td>8.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>15.0</td>\n",
       "      <td>72.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   fruit  order  price\n",
       "0  apple   12.0  160.0\n",
       "1    NaN   15.0   72.5\n",
       "2   kiwi    8.0   80.0\n",
       "3    NaN   15.0   72.5"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi', 'banana'],\n",
    "    'price' : [160,30,80,20],\n",
    "    'order' : [12,30,8,10]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 条件を満たさない行に平均値を入れる\n",
    "df.where(df.price > 50).fillna(df.mean())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     APPLE\n",
       "1    ORANGE\n",
       "2      KIWI\n",
       "dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = {\n",
    "    'fruit' : ['apple', 'orange', 'kiwi'],\n",
    "    'price' : [160,30,80],\n",
    "    'order' : [12,30,8]\n",
    "}\n",
    "\n",
    "df = pd.DataFrame(data)\n",
    "# 小文字を大文字にする\n",
    "df.apply(lambda x: x.fruit.upper(), axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 条件に一致するデータを抽出する\n",
    "\n",
    "* querryメソッド\n",
    "    * データフレームから条件に一致するデータを抽出する\n",
    "        * 比較演算子、論理演算子、四則演算もりようできる\n",
    "        * SQLのWhere句のように使える"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "      <th>col_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_2</th>\n",
       "      <td>9</td>\n",
       "      <td>10</td>\n",
       "      <td>11</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0  col_1  col_2  col_3\n",
       "row_0      1      2      3      4\n",
       "row_1      5      6      7      8\n",
       "row_2      9     10     11     12\n",
       "row_3     13     14     15     16"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num_list = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]\n",
    "df = pd.DataFrame(num_list, index=[\"row_\" + str(i) for i in range(4)], columns=[\"col_\" + str(i) for i in range(4)])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "      <th>col_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0  col_1  col_2  col_3\n",
       "row_1      5      6      7      8\n",
       "row_3     13     14     15     16"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# col_3が8の倍数\n",
    "df_data1 = df.query(\"col_3 % 8 == 0\")\n",
    "df_data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "      <th>col_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0  col_1  col_2  col_3\n",
       "row_1      5      6      7      8\n",
       "row_3     13     14     15     16"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 変数を使う場合(変数の頭に「@」をつける)\n",
    "a = 8\n",
    "df_data1 = df.query(\"col_3 % @a == 0\")\n",
    "df_data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "      <th>col_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0  col_1  col_2  col_3\n",
       "row_3     13     14     15     16"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# col_3が8の倍数かつcol_1が10以上\n",
    "df_data2 = df.query(\"col_3 % 8 == 0 and col_1 >= 10\")\n",
    "df_data2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "      <th>col_3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>13</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       col_0  col_1  col_2  col_3\n",
       "row_3     13     14     15     16"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# inplace = Trueでデータフレームを上書き\n",
    "df.query(\"col_3 % 8 == 0 and col_1 >= 10\", inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 特定の文字列が含まれている行を抽出\n",
    "\n",
    "* col_0列に「A2」という文字列が含まれている行を抽出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      col_0 col_1 col_2\n",
      "row_0    A1    B1    C1\n",
      "row_1    A2    B2    C2\n",
      "row_2    A3    B3    C3\n",
      "row_3    A4    B4    C4\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      col_0 col_1 col_2\n",
       "row_1    A2    B2    C2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "print(df)\n",
    "df[df['col_0'] == 'A2']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 値の変更\n",
    "\n",
    "* atやlocを使って値を変更する\n",
    "* 場合によってはいったんndarryやlistにしてデータフレームに戻した方がやりやすいこともある"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <td>AAA</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>BBB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_2</th>\n",
       "      <td>CCC</td>\n",
       "      <td>CCC</td>\n",
       "      <td>CCC</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>DDD</td>\n",
       "      <td>B4</td>\n",
       "      <td>EEE</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      col_0 col_1 col_2\n",
       "row_0   AAA    B1    C1\n",
       "row_1    A2    B2   BBB\n",
       "row_2   CCC   CCC   CCC\n",
       "row_3   DDD    B4   EEE"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "df.iat[0,0] = 'AAA'\n",
    "df.at['row_1', 'col_2'] = 'BBB'\n",
    "df.loc['row_2', 'col_0':'col_2'] = 'CCC'\n",
    "df.iloc[3,[0,2]] = ['DDD', 'EEE']\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>col_0</th>\n",
       "      <th>col_1</th>\n",
       "      <th>col_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>row_0</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "      <td>C1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_1</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "      <td>C2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_2</th>\n",
       "      <td>A3</td>\n",
       "      <td>AAA</td>\n",
       "      <td>BBB</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>row_3</th>\n",
       "      <td>A4</td>\n",
       "      <td>CCC</td>\n",
       "      <td>DDD</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      col_0 col_1 col_2\n",
       "row_0    A1    B1    C1\n",
       "row_1    A2    B2    C2\n",
       "row_2    A3   AAA   BBB\n",
       "row_3    A4   CCC   DDD"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(\"csv/test.csv\", header = None)\n",
    "df.index = [\"row_0\", \"row_1\", \"row_2\", \"row_3\"]\n",
    "df.columns = [\"col_0\", \"col_1\", \"col_2\"]\n",
    "\n",
    "df.iloc[2:4,1:3] = [['AAA', 'BBB'], ['CCC', 'DDD']]\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 並び替える\n",
    "\n",
    "* inplace=Trueで元のデータフレームを上書きできる"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>ruby</th>\n",
       "      <th>php</th>\n",
       "      <th>python</th>\n",
       "      <th>perl</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>80</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  ruby  php  python  perl\n",
       "0    A   100   40      70    80\n",
       "1    B    60   90      80    10\n",
       "2    C    90   60      60    60\n",
       "3    D    80   70      70    80"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('csv/ruby_1.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>ruby</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  ruby\n",
       "1    B    60\n",
       "3    D    80\n",
       "2    C    90\n",
       "0    A   100"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ruby行でsortする\n",
    "\n",
    "## 昇順(デフォルト)\n",
    "sort_by_ruby = df.sort_values(by='ruby', ascending=True)\n",
    "\n",
    "## 降順\n",
    "#sort_by_ruby = df.sort_values(by='ruby', ascending=False)\n",
    "\n",
    "sort_by_ruby[['name', 'ruby']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 計算結果をデータフレームに追加し、並び替える"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>ruby</th>\n",
       "      <th>php</th>\n",
       "      <th>python</th>\n",
       "      <th>perl</th>\n",
       "      <th>mean</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "      <td>72.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>10</td>\n",
       "      <td>60.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>67.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>80</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "      <td>75.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  ruby  php  python  perl  mean\n",
       "0    A   100   40      70    80  72.5\n",
       "1    B    60   90      80    10  60.0\n",
       "2    C    90   60      60    60  67.5\n",
       "3    D    80   70      70    80  75.0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 平均値を最後に追加する\n",
    "#df['mean'] = df.mean(axis=1)\n",
    "df['mean'] = df.mean(axis=1)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>mean</th>\n",
       "      <th>ruby</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>75.0</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>72.5</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>67.5</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60.0</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  mean  ruby\n",
       "3    D  75.0    80\n",
       "0    A  72.5   100\n",
       "2    C  67.5    90\n",
       "1    B  60.0    60"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 平均値を降順にsortし、平均値が同じ場合はrubyの点数で降順に並べる\n",
    "sort_by_mean = df.sort_values(by=['mean','ruby'], ascending=False)\n",
    "#sort_by_mean = df.sort_values(by='mean', ascending=False)\n",
    "sort_by_mean[['name', 'mean', 'ruby']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>python</th>\n",
       "      <th>ruby</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>70</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>80</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  python  ruby\n",
       "2    C      60    90\n",
       "3    D      70    80\n",
       "0    A      70   100\n",
       "1    B      80    60"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Pythonを昇順にsortする\n",
    "#sort_by_mean = df.sort_values(by='python', ascending=True)\n",
    "\n",
    "# Pythonを昇順にsortし、Pythonが同じ場合はrubyの点数で昇順に並べる\n",
    "sort_by_mean = df.sort_values(by=['python','ruby'], ascending=True)\n",
    "sort_by_mean[['name', 'python', 'ruby']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 演算"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 列を足す"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>ruby</th>\n",
       "      <th>php</th>\n",
       "      <th>python</th>\n",
       "      <th>perl</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A</td>\n",
       "      <td>100</td>\n",
       "      <td>40</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C</td>\n",
       "      <td>90</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>D</td>\n",
       "      <td>80</td>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  ruby  php  python  perl\n",
       "0    A   100   40      70    80\n",
       "1    B    60   90      80    10\n",
       "2    C    90   60      60    60\n",
       "3    D    80   70      70    80"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('csv/ruby_1.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "330"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['ruby'].sum(axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 行を足す"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>ruby</th>\n",
       "      <th>php</th>\n",
       "      <th>python</th>\n",
       "      <th>perl</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>B</td>\n",
       "      <td>60</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  name  ruby  php  python  perl\n",
       "1    B    60   90      80    10"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['name'] == 'B']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    240\n",
       "dtype: int64"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['name'] == 'B'].sum(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 時系列データとしてCSVを読み込む\n",
    "\n",
    "* read_csvはURLを指定するとリモートからデータを取得できる\n",
    "    * オプション\n",
    "        * skiprows=n : ヘッダなど、n行飛ばして読み込む\n",
    "        * index_col=0 : インデックスにしたい列を指定 (ここでは日付列を明示的に指定)\n",
    "        * parse_dates=True : データ中の日付文字列をパースして日付型に変換してロード"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USD</th>\n",
       "      <th>GBP</th>\n",
       "      <th>EUR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2002-04-01</th>\n",
       "      <td>133.15</td>\n",
       "      <td>189.79</td>\n",
       "      <td>116.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2002-04-02</th>\n",
       "      <td>133.20</td>\n",
       "      <td>191.78</td>\n",
       "      <td>117.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2002-04-03</th>\n",
       "      <td>133.20</td>\n",
       "      <td>191.26</td>\n",
       "      <td>116.96</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               USD     GBP     EUR\n",
       "2002-04-01  133.15  189.79  116.12\n",
       "2002-04-02  133.20  191.78  117.18\n",
       "2002-04-03  133.20  191.26  116.96"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "df_pri = df [['USD', 'GBP', 'EUR']]\n",
    "df_pri.head(3)\n",
    "\n",
    "#df = pd.read_csv(csv_url)\n",
    "#df.head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# plotによる可視化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fb75d25d668>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAD6CAYAAAC73tBYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAIABJREFUeJzsnXd4FcXawH+T3hNCEkIINfQaIIAgIEUQUcCCYAcLKGIDFa4Vy4fd69UrFuRiAykqoiBNmvQSMHQwEAIkENIghDRS5vtjTkty0s9JApnf8+SZ3dnZ3VlI9t133iaklGg0Go1GUx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YtdlZG1G1WVUzmkg9Bu1BW2alYIWT14ODBNC9AOL3+0V/WHmarSkWQlAVynl0aYU3gS6tttCl9KmdF3Kuoyszai6DE09pmJDgNutjmcA96FtFNmit5nQcqDMQ09FDFwHxNpq6mNUXUqb0nUp6zKyNqPqMvKjPjfVFW3F3uyzuxWYpj9PAB7Sn/cB5jSbcIPqUtqUrktZl5G1GVWXkR/ndDFJKU9KKUvl6djekZzOxXInECO0IuFz0DYpNUu1K6PqUtqUrktZl5G1GVWXkal3TWqhFSuXaFkJF+rNhWi7V7sAB6WeIE3qZrg5MKoupU3pupR1GVmbUXUZkYbsg6gCHNCyJXbTLe2LQJWUcr35hrYARtWltCldl7IuI2szqi7j0RB/FNqmkCq0nPtTWto/ZnRdSpvSdSnrMrI2o+oy2kPoN6teCCFCgduB96WWU8kQGFUXKG2NQelqGEbVBcbVZlRdRqNBBkKhUCgUlw7NWpNaoVAoFBcOykAoFAqFokaUgVAoFApFjSgDoVAoFIoaUQZCoVAoFDWiDIRCoVAoakQZCIVCoVDUiDIQCoVCoaiR/w/TXpbjzo/NTAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "df_pri = df [['USD', 'GBP', 'EUR']]\n",
    "df_pri['2016':'2017'].plot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 時系列データのサンプリング\n",
    "\n",
    "* サンプリング\n",
    "    * 時間の精度を別の精度に変換する\n",
    "* ダウンサンプリング\n",
    "    * より低い精度に変換する\n",
    "    \n",
    "以下はmedianで中央値を取る例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USD</th>\n",
       "      <th>GBP</th>\n",
       "      <th>EUR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-31</th>\n",
       "      <td>114.700</td>\n",
       "      <td>141.280</td>\n",
       "      <td>122.070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-02-28</th>\n",
       "      <td>113.075</td>\n",
       "      <td>141.510</td>\n",
       "      <td>120.290</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-03-31</th>\n",
       "      <td>113.645</td>\n",
       "      <td>139.485</td>\n",
       "      <td>120.625</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                USD      GBP      EUR\n",
       "2017-01-31  114.700  141.280  122.070\n",
       "2017-02-28  113.075  141.510  120.290\n",
       "2017-03-31  113.645  139.485  120.625"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "df_pri = df [['USD', 'GBP', 'EUR']]\n",
    "df_pri.resample('M').median().tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "diffでひとつ前のデータと差分を取る"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USD</th>\n",
       "      <th>GBP</th>\n",
       "      <th>EUR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-31</th>\n",
       "      <td>-1.830</td>\n",
       "      <td>-3.290</td>\n",
       "      <td>-0.300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-02-28</th>\n",
       "      <td>-1.625</td>\n",
       "      <td>0.230</td>\n",
       "      <td>-1.780</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-03-31</th>\n",
       "      <td>0.570</td>\n",
       "      <td>-2.025</td>\n",
       "      <td>0.335</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              USD    GBP    EUR\n",
       "2017-01-31 -1.830 -3.290 -0.300\n",
       "2017-02-28 -1.625  0.230 -1.780\n",
       "2017-03-31  0.570 -2.025  0.335"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "df_pri = df [['USD', 'GBP', 'EUR']]\n",
    "df_pri.resample('M').median().diff().tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pct_changeで変化率を得る"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>USD</th>\n",
       "      <th>GBP</th>\n",
       "      <th>EUR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-31</th>\n",
       "      <td>-0.015704</td>\n",
       "      <td>-0.022757</td>\n",
       "      <td>-0.002452</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-02-28</th>\n",
       "      <td>-0.014167</td>\n",
       "      <td>0.001628</td>\n",
       "      <td>-0.014582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-03-31</th>\n",
       "      <td>0.005041</td>\n",
       "      <td>-0.014310</td>\n",
       "      <td>0.002785</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 USD       GBP       EUR\n",
       "2017-01-31 -0.015704 -0.022757 -0.002452\n",
       "2017-02-28 -0.014167  0.001628 -0.014582\n",
       "2017-03-31  0.005041 -0.014310  0.002785"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "df_pri = df [['USD', 'GBP', 'EUR']]\n",
    "df_pri.resample('M').median().pct_change().tail(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* rollingで移動する窓関数を使う\n",
    "    * 移動する窓関数\n",
    "        * 30日間など特定の期間をデータを切り出したものを窓と見立てる\n",
    "        * 窓に対して最小値や最大値などの集約関数を計算する機能\n",
    "    * 移動平均の計算に使える"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'pd' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-1bba78a89cda>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mcsv_url\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mdf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcsv_url\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mskiprows\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mindex_col\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mparse_dates\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      5\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'USD'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'GBP'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'EUR'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'USD'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'GBP'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'EUR'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrolling\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwindow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m250\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'pd' is not defined"
     ]
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "csv_url = 'https://www.mizuhobank.co.jp/rate/market/csv/quote.csv'\n",
    "df = pd.read_csv(csv_url, skiprows=2, index_col=0, parse_dates=True)\n",
    "plt.plot(df[['USD', 'GBP', 'EUR']])\n",
    "plt.plot(df[['USD', 'GBP', 'EUR']].rolling(window=250).mean())\n",
    "plot.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# データベースからの読み込み"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    Tables_in_webmail\n",
      "0       article_areas\n",
      "1  article_attributes\n",
      "2  article_categories\n",
      "3        article_docs\n",
      "4    article_sections\n"
     ]
    }
   ],
   "source": [
    "import MySQLdb\n",
    "import pandas.io.sql as mysql\n",
    "\n",
    "### DB接続\n",
    "con = MySQLdb.connect(database='webmail', host='10.136.3.175', user='joruri', passwd='pass', charset='utf8')\n",
    "sql = \"show tables\"\n",
    "\n",
    "### pandasのDataFrameの形でデータを取り出す\n",
    "df = mysql.read_sql(sql, con) \n",
    "print (df.head(5))\n",
    "con.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th>sort_no</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>INBOX</th>\n",
       "      <th>1</th>\n",
       "      <td>4498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Drafts</th>\n",
       "      <th>3</th>\n",
       "      <td>3745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star</th>\n",
       "      <th>2</th>\n",
       "      <td>3745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sent</th>\n",
       "      <th>4</th>\n",
       "      <td>3745</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Archives</th>\n",
       "      <th>5</th>\n",
       "      <td>3740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">Trash</th>\n",
       "      <th>6</th>\n",
       "      <td>3645</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sent</th>\n",
       "      <th>5</th>\n",
       "      <td>213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Archives</th>\n",
       "      <th>6</th>\n",
       "      <td>213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Drafts</th>\n",
       "      <th>4</th>\n",
       "      <td>213</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    id\n",
       "name     sort_no      \n",
       "INBOX    1        4498\n",
       "Drafts   3        3745\n",
       "Star     2        3745\n",
       "Sent     4        3745\n",
       "Archives 5        3740\n",
       "Trash    6        3645\n",
       "         7         243\n",
       "Sent     5         213\n",
       "Archives 6         213\n",
       "Drafts   4         213"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import MySQLdb\n",
    "import pandas.io.sql as mysql\n",
    "con = MySQLdb.connect(database='webmail', host='10.136.3.175', user='joruri', passwd='pass', charset='utf8')\n",
    "gw_webmail_mailboxes = mysql.read_sql(\"select * from gw_webmail_mailboxes;\", con) \n",
    "\n",
    "### idとstateが同じものの数をカウント\n",
    "#print (df[['id','state','name_en']].groupby(['id', 'state']).count().head(5))\n",
    "\n",
    "### nameとsort_noを1セット(集計をしない列)としてid(集計対象の列)の数をカウント\n",
    "state_disabled_enabled = (gw_webmail_mailboxes[['id','name','sort_no']].groupby(['name','sort_no']).count())\n",
    "#state_disabled_enabled.head(5)\n",
    "\n",
    "### idの数が多い順でsort\n",
    "state_disabled_enabled.sort_values(by='id', ascending=False).head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# データフレームのマージ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "No module named 'MySQLdb'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-10-99bdecf210dc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mMySQLdb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msql\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mmysql\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[0mcon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMySQLdb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconnect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdatabase\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'webmail'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhost\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'10.136.3.175'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0muser\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'joruri'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpasswd\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'pass'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcharset\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'utf8'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0msys_users\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmysql\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread_sql\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"select * from sys_users;\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcon\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;31m#sys_users.head(3)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mImportError\u001b[0m: No module named 'MySQLdb'"
     ]
    }
   ],
   "source": [
    "import MySQLdb\n",
    "import pandas.io.sql as mysql\n",
    "con = MySQLdb.connect(database='webmail', host='10.136.3.175', user='joruri', passwd='pass', charset='utf8')\n",
    "sys_users = mysql.read_sql(\"select * from sys_users;\", con) \n",
    "#sys_users.head(3)\n",
    "sys_groups = mysql.read_sql(\"select * from sys_groups;\", con) \n",
    "#sys_groups.head(3)\n",
    "sys_users_groups = mysql.read_sql(\"select * from sys_users_groups;\", con) \n",
    "#sys_users_groups.head(3)\n",
    "\n",
    "### sys_usersとsys_users_groupsをidとuser_idが一致する行で内部結合\n",
    "sys_users_sys_users_groups = pd.merge(sys_users, sys_users_groups, left_on='id', right_on='user_id', how='inner')\n",
    "#sys_users_sys_users_groups.head(3)\n",
    "\n",
    "### 上記の結果に対して、toup_idとsys_groupsのidが一致する行で内部結合\n",
    "sys_users_sys_users_groups_sys_groups = pd.merge(sys_users_sys_users_groups, sys_groups, left_on='group_id', right_on='id', how='inner')\n",
    "sys_users_sys_users_groups_sys_groups.head(3)\n",
    "\n",
    "### ユーザ名とグループを表示\n",
    "#sys_users_sys_users_groups_sys_groups[['name_x','name_y']].head(10)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# グループ集計"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x7fc1ceb01240>"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAD8CAYAAABthzNFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFcdJREFUeJzt3X2QXXWd5/H3xwSNGCQKbZYiQKKDjMwATuwgK5iNss5E\nGAhsuUCcxcBSBmtxlB0tBXdqoGqWLSwZGbRWazKCogtGBlAisrODrIwPpYREUSCRJSWIHUEiPjIM\nhMh3/7gnoUlO6Jvuvn076ferquue8ztP3z456U/9ztNNVSFJ0vZe0O8CJEmTkwEhSWplQEiSWhkQ\nkqRWBoQkqZUBIUlqZUBIklr1LCCSXJXk0ST3tEx7X5JKsn8zniQfS7IhyQ+SzO9VXZKk7vSyB/EZ\nYPH2jUkOAv4YeGhY81uBQ5uf5cAne1iXJKkL03u14qr6epK5LZMuBz4A3DSsbQnw2eo81v2dJLOS\nHFBVDz/fNvbff/+aO7dtE5KknVm7du3Pq2pgpPl6FhBtkiwBNlbV95MMn3Qg8JNh40NN2w4BkWQ5\nnV4GBx98MGvWrOldwZK0B0ry427mm7CL1En2Bj4E/NVY1lNVK6pqsKoGBwZGDEBJ0ihNZA/iVcA8\nYGvvYQ7w3SRHAxuBg4bNO6dpkyT1yYT1IKrq7qp6RVXNraq5dE4jza+qR4BVwDuau5mOAX490vUH\nSVJv9awHkeTzwCJg/yRDwEVVdeVOZr8FOAHYADwBnN2ruiTtfp5++mmGhoZ48skn+13KbmXGjBnM\nmTOHvfbaa1TL9/IupqUjTJ87bLiA83pVi6Td29DQEPvssw9z585luxtctBNVxWOPPcbQ0BDz5s0b\n1Tp8klrSpPfkk0+y3377GQ67IAn77bffmHpdBoSk3YLhsOvGus8MCElSqwl9UE6SxsPcC74yrut7\n8NITx3V9e4opGxDjfYDtCg9GSaNxwgkncO211zJr1qzntF988cXMnDmT97///eO6vSkbEJI0nrZs\n2cL06b39k3rLLbf0dP3b8xqEJHXhr//6rznssMM47rjjWLp0KZdddhmLFi3i/PPPZ3BwkCuuuIIH\nH3yQN7/5zRx55JEcf/zxPPRQ56XVZ511Ftdff/22dc2cOROA22+/nYULF3LiiSdy2GGH8a53vYtn\nnnlmpzXMnTuXn//85wBccsklvPrVr+a4447jvvvu68nvbA9CkkZw5513csMNN/D973+fp59+mvnz\n5/O6170OgM2bN297aehJJ53EsmXLWLZsGVdddRXvec97+NKXvvS86169ejXr1q3jkEMOYfHixdx4\n44287W1ve95l1q5dy8qVK7nrrrvYsmXLc+oZT/YgJGkE3/rWt1iyZAkzZsxgn3324aSTTto27fTT\nT982/O1vf5u3v/3tAJx55pl885vfHHHdRx99NK985SuZNm0aS5cu7WqZb3zjG5x66qnsvffevPSl\nL+Xkk08exW81MgNCksbgJS95yYjzTJ8+fdupo2eeeYbNmzdvm7b9swqT6XkPTzFJ2u1M9J2Axx57\nLOeeey4XXnghW7Zs4eabb2b58uU7zPeGN7yBlStXcuaZZ3LNNdfwxje+EehcO1i7di2nnXYa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mv9fe5otwPuq6nDgGOC85nefEsfKlAoI\nhr3Ko6o2A1tf5aHOfri6Gb4aOKWPtfRcVX0d+MV2zTvbB0uAz1bHd4BZSQ6YmEonzk72yc4sAVZW\n1VNV9QCwgc7/rz1KVT1cVd9thn8LrKfzdocpcaxMtYDwVR4dBfxTkrXNk+kAs6vq4Wb4EWB2f0rr\nq53tg6l+3Ly7OV1y1bBTj1NunySZC/wRcAdT5FiZagGhjuOqaj6d7vB5SRYOn1idW9um9O1t7oNt\nPgm8Cngt8DDwN/0tpz+SzARuAM6vqt8Mn7YnHytTLSBGfJXHVFBVG5vPR4Ev0jk18LOtXeHm89H+\nVdg3O9sHU/a4qaqfVdXvquoZ4O959jTSlNknSfaiEw7XVNWNTfOUOFamWkBM+Vd5JHlJkn22DgN/\nDNxDZz8sa2ZbBtzUnwr7amf7YBXwjuYOlWOAXw87vbBH2+78+al0jhXo7JMzkrwoyTw6F2VXT3R9\nvZYkwJXA+qr66LBJU+JYmXRPUveSr/IAOudKv9g57pkOXFtV/5jkTuC6JOcAPwZO62ONPZfk88Ai\nYP8kQ8BFwKW074NbgBPoXIh9Ajh7wgueADvZJ4uSvJbOKZQHgXMBqureJNfR+a6WLcB5VfW7ftTd\nY8cCZwJ3J7mrafsQU+RY8UlqSVKrqXaKSZLUJQNCktTKgJAktTIgJEmtDAhJUisDQpLUyoCQJLUy\nICRJrf4/NCQvZMj4Tw8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fc1ce9f9278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import MySQLdb\n",
    "import pandas.io.sql as mysql\n",
    "\n",
    "### 全ての列を表示するためのオプション\n",
    "#pd.options.display.max_columns = None\n",
    "\n",
    "con = MySQLdb.connect(database='webmail', host='10.136.3.175', user='joruri', passwd='pass', charset='utf8')\n",
    "sys_users = mysql.read_sql(\"select * from sys_users;\", con) \n",
    "sys_groups = mysql.read_sql(\"select * from sys_groups;\", con) \n",
    "sys_users_groups = mysql.read_sql(\"select * from sys_users_groups;\", con) \n",
    "sys_users_sys_users_groups = pd.merge(sys_users, sys_users_groups, left_on='id', right_on='user_id', how='inner')\n",
    "sys_users_sys_users_groups_sys_groups = pd.merge(sys_users_sys_users_groups, sys_groups, left_on='group_id', right_on='id', how='inner')\n",
    "\n",
    "### カラム名を取得(確認)\n",
    "#sys_users_sys_users_groups_sys_groups.columns\n",
    "#sys_users_sys_users_groups_sys_groups[['group_id','name_x','name_y']].head(5)\n",
    "\n",
    "### group_idの数をカウント\n",
    "group_count = sys_users_sys_users_groups_sys_groups[['group_id','name_y']].groupby(['name_y']).count()\n",
    "\n",
    "### group_idの数が多い順に表示\n",
    "#group_count.sort_values(by='group_id', ascending=False).head(5)\n",
    "\n",
    "### ヒストグラムの表示(グループ数の頻度)\n",
    "group_count.plot(kind='hist')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tips"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## 全ての列を表示する"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id_x</th>\n",
       "      <th>air_login_id</th>\n",
       "      <th>state</th>\n",
       "      <th>created_at_x</th>\n",
       "      <th>updated_at_x</th>\n",
       "      <th>ldap</th>\n",
       "      <th>ldap_version</th>\n",
       "      <th>auth_no</th>\n",
       "      <th>name</th>\n",
       "      <th>name_en</th>\n",
       "      <th>account</th>\n",
       "      <th>password</th>\n",
       "      <th>mobile_access</th>\n",
       "      <th>mobile_password</th>\n",
       "      <th>email</th>\n",
       "      <th>remember_token</th>\n",
       "      <th>remember_token_expires_at</th>\n",
       "      <th>kana</th>\n",
       "      <th>sort_no</th>\n",
       "      <th>official_position</th>\n",
       "      <th>assigned_job</th>\n",
       "      <th>group_s_name</th>\n",
       "      <th>id_y</th>\n",
       "      <th>created_at_y</th>\n",
       "      <th>updated_at_y</th>\n",
       "      <th>user_id</th>\n",
       "      <th>group_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>None</td>\n",
       "      <td>enabled</td>\n",
       "      <td>2010-08-19 16:39:05</td>\n",
       "      <td>2016-04-18 21:37:24</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>5</td>\n",
       "      <td>システム管理者</td>\n",
       "      <td></td>\n",
       "      <td>admin</td>\n",
       "      <td>w4#757xf</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1234</td>\n",
       "      <td>admin@192.168.32.243</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-08-19 16:39:05</td>\n",
       "      <td>2010-08-19 16:39:05</td>\n",
       "      <td>1</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   id_x air_login_id    state        created_at_x        updated_at_x  ldap  \\\n",
       "0     1         None  enabled 2010-08-19 16:39:05 2016-04-18 21:37:24     0   \n",
       "\n",
       "  ldap_version  auth_no     name name_en account  password  mobile_access  \\\n",
       "0         None        5  システム管理者           admin  w4#757xf            1.0   \n",
       "\n",
       "  mobile_password                 email remember_token  \\\n",
       "0            1234  admin@192.168.32.243           None   \n",
       "\n",
       "  remember_token_expires_at  kana sort_no official_position assigned_job  \\\n",
       "0                      None  None    None              None         None   \n",
       "\n",
       "  group_s_name  id_y        created_at_y        updated_at_y  user_id  \\\n",
       "0         None     1 2010-08-19 16:39:05 2010-08-19 16:39:05        1   \n",
       "\n",
       "   group_id  \n",
       "0        57  "
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import MySQLdb\n",
    "import pandas.io.sql as mysql\n",
    "\n",
    "### 全ての列を表示するためのオプション\n",
    "pd.options.display.max_columns = None\n",
    "\n",
    "con = MySQLdb.connect(database='webmail', host='10.136.3.175', user='joruri', passwd='pass', charset='utf8')\n",
    "sys_users = mysql.read_sql(\"select * from sys_users;\", con) \n",
    "sys_groups = mysql.read_sql(\"select * from sys_groups;\", con) \n",
    "pd.merge(sys_users, sys_users_groups, left_on='id', right_on='user_id', how='inner').head(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## カラム内の表示文字数を増やす\n",
    "\n",
    "* デフォルトは50\n",
    "    * 半角文字や全角文字で制限の挙動が違ったりするので都度確認する方がよさげ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    0\n",
       "0                                                   1\n",
       "1  あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこ\n",
       "2                                                   3"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "### 50文字\n",
    "a='あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこ'\n",
    "df = pd.DataFrame([1,a,3])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかき...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    0\n",
       "0                                                   1\n",
       "1  あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかき...\n",
       "2                                                   3"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "a='あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあ'\n",
    "### 51文字\n",
    "df = pd.DataFrame([1,a,3])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     0\n",
       "0                                                    1\n",
       "1  あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあ\n",
       "2                                                    3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "a='あいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあいうえおかきくけこあ'\n",
    "\n",
    "### 52に設定\n",
    "pd.set_option(\"display.max_colwidth\", 52)\n",
    "\n",
    "### 51文字\n",
    "df = pd.DataFrame([1,a,3])\n",
    "df"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
